(function($){
	
	function view_all(){
	
		if ($.ajax) {
			
			$.ajax({
				type: "GET",
				url: "couchdb/hmodevhouse/_design/assistence/_view/all",
				contentType: "application/json;",
				data: "{}",
				dataType: "json",
				error: function(error){
					alert("Error");
				},
				success: function(success){
					var list = $("#attendents");
					var rows = success.rows;
					var attendee;
					
					$("#noAssistance").text(rows.length);
					
					var lookForAt = /^@+/;
					$(rows).each(function(index, value){
						var data = value.value;
						
						if(!data.personal.twitterHandle.match(lookForAt))
							data.personal.twitterHandle = "@" + data.personal.twitterHandle;   
						
						attendee = $.UL({}, $.LI({}, data.personal.name),
														 $.LI({}, $.A({
														 						href: "http://twitter.com/" + data.personal.twitterHandle
																			}, 
														 					data.personal.twitterHandle)),
														 $.LI({}, 	$.LABEL({ 'class': "subjectLbl"}, "Que Haré Hoy: "), 
														 				data.todaysWork.subject == "" ? "No les quiero decir =P"
																															: data.todaysWork.subject)
													);
													
						$(list).append($.LI({}, attendee ));
					});
				}
			});
		}
	};
	
	//On Ready
	$(document).ready(function(){
		view_all();
	});
	
})(jQuery);